package com.beibojd.service.impl;

import com.beibojd.dao.CustomerMapper;
import com.beibojd.pojo.Customer;
import com.beibojd.pojo.Result;
import com.beibojd.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 洪耀荣
 * @Date: 2021-06-24 13:02:10
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public List<Customer> selectAllCustomer() {
        List<Customer> customers=customerMapper.selectAll();
        return customers;
    }

    @Override
    public Customer selectCustomerById(Integer id) {
        Customer customer=customerMapper.selectByPrimaryKey(id);
        return customer;
    }

    @Override
    public Result<Customer> selectCustomerByName(String name) {
        Customer customer=customerMapper.selectOneByExample(name);
        return new Result<Customer>(" 查询成功",customer);
    }

    @Override
    public Result<Customer> selectCustomerByFirstName(String firstName) {
        Customer customer=customerMapper.selectOneByExample(firstName);
        return new Result<Customer>(" 查询成功",customer);
    }

    @Override
    public Result updateCustomer(Customer customer) {
        customerMapper.updateByPrimaryKey(customer);
        return new Result("更新成功");
    }


    @Override
    public Result addCustomer(Customer customer) {
        System.out.println("service成功获取");
        System.out.println(customer.toString());
        customerMapper.insert(customer);
        System.out.println("service成功执行");
        return new Result("添加成功");
    }

    @Override
    public Result delCustomer(Integer id) {
        customerMapper.deleteByPrimaryKey(id);
        System.out.println("删除"+id+"成功");
        return new Result("删除成功");
    }
}
